package com.zds;

import com.zds.util.JedisConnectFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;

import java.util.Map;
import java.util.Set;

/**
 * @className:test
 * @date: 2025/2/8 下午5:45
 * @description:
 */
public class test {
    private Jedis jedis;

    @BeforeEach
    void setUp() throws Exception {
        //建立连接
        jedis = JedisConnectFactory.getJedisPool();
//        选择一个库
        jedis.select(0);
    }
    @Test
    void testString(){
        String result = jedis.set("hello","world");
        System.out.println("result = "+result);
        //获取数据
        String name = jedis.get("hello");
        System.out.println("name = "+name);
    }

    @Test
    void testSet(){

    }
    @Test
    void testList(){

    }
    @Test
    void testHash(){
//        jedis.hset("hash","key","value");
        Set<String> hkeys = jedis.hkeys("hash:user:1");
        hkeys.forEach(System.out::println);
        Map<String, String> stringStringMap = jedis.hgetAll("hash:user:1");
        stringStringMap.forEach((k,v)->{
            System.out.println(k+":"+v);
        });


    }
    @Test
    void testKey(){

    }


    @AfterEach
    void tearDown() throws Exception {
        if (jedis != null) {
            jedis.close();
        }

    }
}
